package com.sinping.qh.service.admin.lab.impl;

import com.sinping.qh.api.support.Const;
import com.sinping.qh.api.support.ConstEum;
import com.sinping.qh.api.support.ResDto;
import com.sinping.qh.domain.lab.InspectItemThreeDomain;
import com.sinping.qh.domain.lab.InspectItemTwoDomain;
import com.sinping.qh.domain.lab.LabInspectItemDomain;
import com.sinping.qh.domain.lab.LabInspectItemRelationDomain;
import com.sinping.qh.dto.admin.lab.InspectItemThreeDto;
import com.sinping.qh.dto.admin.lab.InspectItemTwoDto;
import com.sinping.qh.dto.admin.lab.LabInspectItemDto;
import com.sinping.qh.dto.admin.lab.LabInspectItemRelationDto;
import com.sinping.qh.dto.auth.UserSessionDTO;
import com.sinping.qh.query.lab.InspectItemQuery;
import com.sinping.qh.query.lab.InspectItemTwoQuery;
import com.sinping.qh.repository.mongo.lab.LabInspectItemRelationRepository;
import com.sinping.qh.repository.mongo.lab.LabInspectItemRepository;
import com.sinping.qh.service.MongoManager;
import com.sinping.qh.service.admin.lab.ILabInspectItemService;
import com.sinping.qh.service.auth.ISessionService;
import com.sinping.qh.utils.mapper.BeanMapper;
import com.sinping.qh.utils.mapper.JsonMapper;
import com.sinping.qh.utils.misc.IdGenerator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author jiahuaiqing
 * @create 2018/6/1
 */
@Service
public class LabInspectItemServiceImpl implements ILabInspectItemService {

    @Autowired
    LabInspectItemRepository labInspectItemRepository;

    @Autowired
    LabInspectItemRelationRepository labInspectItemRelationRepository;

    @Autowired
    MongoManager mongoManager;

    @Qualifier("sessionServiceRedisImpl")
    @Autowired
    private ISessionService iSessionService;

    @Override
    public ResDto addInspectItemOne(HttpServletRequest request, LabInspectItemDto labInspectItemDto) {
        try {
            String token = request.getHeader(Const.TOKEN_NAME);
            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
            if (userSessionDTO == null) {
                return new ResDto(Const.PARAM_ERROR, "用户未登录");
            }
            //验证参数
            if (StringUtils.isBlank(userSessionDTO.getId())) {
                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
            }

            String itemCategory = labInspectItemDto.getItemCategory();
            String itemName = labInspectItemDto.getItemName();
            String itemSubcategory = labInspectItemDto.getItemSubcategory();
            LabInspectItemDomain domain = labInspectItemRepository.findByItemNameAndItemCategoryAndItemSubcategory(itemName, itemCategory, itemSubcategory);
            if (domain != null) {
                return new ResDto(Const.SERVER_ERROR, "检查项已经存在");
            }
            LabInspectItemDomain dtoTODomain = BeanMapper.map(labInspectItemDto, LabInspectItemDomain.class);
            dtoTODomain.setId(IdGenerator.uuid2());
            dtoTODomain.setItemName(itemName);
            dtoTODomain.setItemCategory(itemCategory);
            dtoTODomain.setItemSubcategory(itemSubcategory);
            dtoTODomain.setCreateUserId(userSessionDTO.getId());
            dtoTODomain.setStatus("0");
            dtoTODomain.setGmtCreated(new Date());
            dtoTODomain.setGmtModified(new Date());
            LabInspectItemDomain save = labInspectItemRepository.save(dtoTODomain);
            if (save == null) {
                return new ResDto(Const.SERVER_ERROR, "一级检查项添加失败");
            }
            return new ResDto(Const.SUCCESS, "一级检查项添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SUCCESS, "一级检查项添加异常");
        }

    }

    @Override
    public ResDto addInspectItemTwo(HttpServletRequest request, LabInspectItemDto labInspectItemDto) {
        try {
            String token = request.getHeader(Const.TOKEN_NAME);
            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
            if (userSessionDTO == null) {
                return new ResDto(Const.PARAM_ERROR, "用户未登录");
            }
            //验证参数
            if (StringUtils.isBlank(userSessionDTO.getId())) {
                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
            }

            String id = labInspectItemDto.getId();
            String itemName = labInspectItemDto.getItemName();
            LabInspectItemDomain one = labInspectItemRepository.findOne(id);
            if (one == null) {
                return new ResDto(Const.SERVER_ERROR, "检查项id不存在");
            }
            List<InspectItemTwoDomain> inspectItemTwoDomains = one.getInspectItemTwoLists();
            if (null == inspectItemTwoDomains || inspectItemTwoDomains.isEmpty()) {
                inspectItemTwoDomains = new ArrayList<InspectItemTwoDomain>();
            }
            InspectItemTwoDomain inspectItemTwoDomain = new InspectItemTwoDomain();
            inspectItemTwoDomain.setId(IdGenerator.uuid2());
            inspectItemTwoDomain.setItemName(itemName);
            inspectItemTwoDomain.setCreateUserId(userSessionDTO.getId());
            //inspectItemTwoDomain.setUpdateUserId("aaa");
            inspectItemTwoDomain.setStatus("0");
            inspectItemTwoDomain.setGmtCreated(new Date());
            inspectItemTwoDomain.setGmtModified(new Date());
            inspectItemTwoDomains.add(inspectItemTwoDomain);
            one.setInspectItemTwoLists(inspectItemTwoDomains);
            LabInspectItemDomain save = labInspectItemRepository.save(one);
            if (save == null) {
                return new ResDto(Const.SERVER_ERROR, "二级检查项添加失败");
            }
            return new ResDto(Const.SUCCESS, "二级检查项添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SUCCESS, "二级检查项添加异常");
        }
    }

    @Override
    public ResDto addInspectItemThree(HttpServletRequest request, LabInspectItemDto labInspectItemDto) {
        try {
            String token = request.getHeader(Const.TOKEN_NAME);
            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
            if (userSessionDTO == null) {
                return new ResDto(Const.PARAM_ERROR, "用户未登录");
            }
            //验证参数
            if (StringUtils.isBlank(userSessionDTO.getId())) {
                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
            }

            String id = labInspectItemDto.getId();
            String itemName = labInspectItemDto.getItemName();
            //检查一级
            LabInspectItemDomain one = labInspectItemRepository.findOne(id);
            if (one == null) {
                return new ResDto(Const.SERVER_ERROR, "检查项id不存在");
            }
            List<InspectItemTwoDomain> twoDomainLists = one.getInspectItemTwoLists();
            if (null == twoDomainLists || twoDomainLists.isEmpty()) {
                return new ResDto(Const.SERVER_ERROR, "二级检查项不存在,无法添加隐患描述");
            }
            //检查二级
            for (InspectItemTwoDomain two : twoDomainLists) {
                if (labInspectItemDto.getItemIdTwo().equals(two.getId())) {
                    //检查三级隐患
                    List<InspectItemThreeDomain> threeDomainLists = two.getInspectItemThreeLists();
                    if (null == threeDomainLists || threeDomainLists.isEmpty()) {
                        threeDomainLists = new ArrayList<InspectItemThreeDomain>();
                    }
                    InspectItemThreeDomain threeDomain = new InspectItemThreeDomain();
                    threeDomain.setId(IdGenerator.uuid2());
                    threeDomain.setItemDesc(itemName);
                    threeDomain.setCreateUserId(userSessionDTO.getId());
                    //threeDomain.setUpdateUserId("aaa");
                    threeDomain.setStatus("0");
                    threeDomain.setGmtCreated(new Date());
                    threeDomain.setGmtModified(new Date());
                    threeDomainLists.add(threeDomain);
                    two.setInspectItemThreeLists(threeDomainLists);
                }
            }
            one.setInspectItemTwoLists(twoDomainLists);
            LabInspectItemDomain save = labInspectItemRepository.save(one);
            if (save == null) {
                return new ResDto(Const.SERVER_ERROR, "隐患记录添加失败");
            }
            return new ResDto(Const.SUCCESS, "隐患记录添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SUCCESS, "隐患记录添加异常");
        }

    }

    @Override
    public ResDto updateInspectItemOne(HttpServletRequest request, LabInspectItemDto labInspectItemDto) {
        try {
            String token = request.getHeader(Const.TOKEN_NAME);
            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
            if (userSessionDTO == null) {
                return new ResDto(Const.PARAM_ERROR, "用户未登录");
            }
            //验证参数
            if (StringUtils.isBlank(userSessionDTO.getId())) {
                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
            }

            LabInspectItemDomain labInspectItemDomain = labInspectItemRepository.findOne(labInspectItemDto.getId());
            if (labInspectItemDomain == null) {
                return new ResDto(Const.SERVER_ERROR, "id不存在");
            }
            labInspectItemDomain.setItemName(labInspectItemDto.getItemName());
            labInspectItemDomain.setItemSubcategory(labInspectItemDto.getItemSubcategory());
            labInspectItemDomain.setItemCategory(labInspectItemDto.getItemCategory());
            labInspectItemDomain.setUpdateUserId(userSessionDTO.getId());
            labInspectItemDomain.setGmtModified(new Date());
            LabInspectItemDomain save = labInspectItemRepository.save(labInspectItemDomain);
            if (save == null) {
                return new ResDto(Const.SERVER_ERROR, "一级检查项修改失败");
            }
            return new ResDto(Const.SUCCESS, "一级检查项修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SERVER_ERROR, "更新一级检查项异常");
        }

    }

    @Override
    public ResDto updateInspectItemTwo(HttpServletRequest request, LabInspectItemDto labInspectItemDto) {
        try {
            String token = request.getHeader(Const.TOKEN_NAME);
            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
            if (userSessionDTO == null) {
                return new ResDto(Const.PARAM_ERROR, "用户未登录");
            }
            //验证参数
            if (StringUtils.isBlank(userSessionDTO.getId())) {
                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
            }

            LabInspectItemDomain one = labInspectItemRepository.findOne(labInspectItemDto.getId());
            if (one == null) {
                return new ResDto(Const.SERVER_ERROR, "id不存在");
            }
            List<InspectItemTwoDomain> twoList = one.getInspectItemTwoLists();
            if (null == twoList || twoList.isEmpty()) {
                return new ResDto(Const.SERVER_ERROR, "没有这个二级检查项");
            }

            int index = -1;
            InspectItemTwoDomain twoCopy = null;
            for (InspectItemTwoDomain two:twoList) {
                if (two.getId().equals(labInspectItemDto.getItemIdTwo())) {
                    index = twoList.indexOf(two);
                    two.setItemName(labInspectItemDto.getItemName());
                    two.setUpdateUserId(userSessionDTO.getId());
                    two.setGmtModified(new Date());
                    twoCopy = two;
                }
            }
            if (index == -1) {
                return new ResDto(Const.SERVER_ERROR, "二级检查项id不存在");
            }
            if (null == twoCopy) {
                return new ResDto(Const.SERVER_ERROR, "二级检查项不存在");
            }
            twoList.set(index, twoCopy);
            one.setInspectItemTwoLists(twoList);
            LabInspectItemDomain save = labInspectItemRepository.save(one);
            if (save == null) {
                return new ResDto(Const.SERVER_ERROR, "二级检查项修改失败");
            }
            return new ResDto(Const.SUCCESS, "二级检查项修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SERVER_ERROR, "更新二级检查项异常");
        }
    }

    @Override
    public ResDto updateInspectItemThree(HttpServletRequest request, LabInspectItemDto labInspectItemDto) {
        try {
            String token = request.getHeader(Const.TOKEN_NAME);
            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
            if (userSessionDTO == null) {
                return new ResDto(Const.PARAM_ERROR, "用户未登录");
            }
            //验证参数
            if (StringUtils.isBlank(userSessionDTO.getId())) {
                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
            }

            LabInspectItemDomain one = labInspectItemRepository.findOne(labInspectItemDto.getId());
            if (one == null) {
                return new ResDto(Const.SERVER_ERROR, "id不存在");
            }
            List<InspectItemTwoDomain> twoList = one.getInspectItemTwoLists();
            if (null == twoList || twoList.isEmpty()) {
                return new ResDto(Const.SERVER_ERROR, "没有这个二级检查项");
            }
            int indexII = -1;
            int indexIII = -1;
            for (InspectItemTwoDomain two :twoList) {
                if (two.getId().equals(labInspectItemDto.getItemIdTwo())) {
                    indexII = twoList.indexOf(two);
                    List<InspectItemThreeDomain> threeLists = two.getInspectItemThreeLists();
                    if (null == threeLists || threeLists.isEmpty()) {
                        return new ResDto(Const.SERVER_ERROR, "没有这个三级检查项");
                    }
                    for ( InspectItemThreeDomain three :threeLists) {
                        if (three.getId().equals(labInspectItemDto.getItemIdThree())) {
                            indexIII = threeLists.indexOf(three);
                            three.setItemDesc(labInspectItemDto.getItemName());
                            three.setUpdateUserId(userSessionDTO.getId());
                            three.setGmtModified(new Date());
                            threeLists.set(indexIII, three);
                        }
                    }
                    two.setInspectItemThreeLists(threeLists);
                }
            }
            if (indexII == -1) {
                return new ResDto(Const.SERVER_ERROR, "二级检查项id不存在");
            }
            if (indexIII == -1) {
                return new ResDto(Const.SERVER_ERROR, "三级检查项id不存在");
            }
            one.setInspectItemTwoLists(twoList);
            LabInspectItemDomain save = labInspectItemRepository.save(one);
            if (save == null) {
                return new ResDto(Const.SERVER_ERROR, "三级检查项修改失败");
            }
            return new ResDto(Const.SUCCESS, "三级检查项修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SERVER_ERROR, "更新三级检查项数据异常");
        }

    }

    @Override
    public ResDto getInspectItemList(LabInspectItemDto labInspectItemDto) {
        String itemName = labInspectItemDto.getItemName();
        String itemSubcategory = labInspectItemDto.getItemSubcategory();
        String itemDesc = labInspectItemDto.getItemDesc();
        try {
            List<LabInspectItemDto> labInspectItemDtoList = null;
            if (!StringUtils.isNotBlank(itemName) && !StringUtils.isNotBlank(itemSubcategory) && !StringUtils.isNotBlank(itemDesc)) {
                //查全部
                List<LabInspectItemDomain> all = labInspectItemRepository.findAll();
                if (null == all || all.isEmpty()) {
                    return new ResDto(Const.SERVER_ERROR, "暂无数据");
                }
                List<LabInspectItemDomain> labInspectItemList = (all);
                labInspectItemDtoList = BeanMapper.mapList(labInspectItemList, LabInspectItemDto.class);
                return getFilterInspectItemList(labInspectItemDtoList);
            }
            //只查隐患描述(三级)
            if (StringUtils.isNotBlank(itemDesc) && !StringUtils.isNotBlank(itemSubcategory)) {
                //db.getCollection('tb_lab_inspect_item').find({"inspect_item_two":{"$elemMatch":{"item_name":"ni号"}}})
                //db.getCollection('tb_lab_inspect_item').find({"inspect_item_two.inspect_item_three.item_name":"未建立院系安全责任体系"})
                InspectItemTwoQuery inspectItemQuery = BeanMapper.map(labInspectItemDto, InspectItemTwoQuery.class);
                List<LabInspectItemDomain> labInspectItemDomains = mongoManager.find(inspectItemQuery, LabInspectItemDomain.class);
                labInspectItemDtoList = BeanMapper.mapList(labInspectItemDomains, LabInspectItemDto.class);
                return getFilterInspectItemList(labInspectItemDtoList);
            }
            //查询分类不空名称为空和分类不空名称不空两种情况
            InspectItemQuery inspectItemQuery = BeanMapper.map(labInspectItemDto, InspectItemQuery.class);
            List<LabInspectItemDomain> labInspectItemDomains = mongoManager.find(inspectItemQuery, LabInspectItemDomain.class);
            labInspectItemDtoList = BeanMapper.mapList(labInspectItemDomains, LabInspectItemDto.class);
            return getFilterInspectItemList(labInspectItemDtoList);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SERVER_ERROR, "查询数据异常");
        }

    }


    /**
     * 获取危险源隐患库--根据分类只显示一级和二级检查项
     *
     * @param subcategory
     * @return
     */
    @Override
    public ResDto getInspectItemList(String[] subcategory) {
        try {
            List<LabInspectItemDomain> inspectItemDomainList = labInspectItemRepository.findByItemSubcategory(subcategory);
            if (null == inspectItemDomainList || inspectItemDomainList.isEmpty()) {
                return new ResDto(Const.SERVER_ERROR, "暂无数据");
            }
            List<LabInspectItemDto> inspectItemDtoList = BeanMapper.mapList(inspectItemDomainList, LabInspectItemDto.class);
            return getFilterInspectItemList_two(inspectItemDtoList);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SERVER_ERROR, "数据处理异常");
        }

    }

    @Override
    public ResDto deleteLabInspectItemById(HttpServletRequest request, LabInspectItemDto labInspectItemDto) {
        String token = request.getHeader(Const.TOKEN_NAME);
        UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
        if (userSessionDTO == null) {
            return new ResDto(Const.PARAM_ERROR, "用户未登录");
        }
        //验证参数
        if (StringUtils.isBlank(userSessionDTO.getId())) {
            return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
        }

        String id = labInspectItemDto.getId();
        String idTwo = labInspectItemDto.getItemIdTwo();
        String idThree = labInspectItemDto.getItemIdThree();
        int indexII = -1;
        int indexIII = -1;
        try {
            if (StringUtils.isNotBlank(idThree)) {
                //直接删除三级
                if (!StringUtils.isNotBlank(idTwo)) {
                    return new ResDto(Const.SERVER_ERROR, "二级id不为空");
                }
                LabInspectItemDomain one = labInspectItemRepository.findOne(id);
                if (one == null) {
                    return new ResDto(Const.SERVER_ERROR, "一级id不存在");
                }
                List<InspectItemTwoDomain> twoDomains = one.getInspectItemTwoLists();
                if (null == twoDomains || twoDomains.isEmpty()) {
                    return new ResDto(Const.SERVER_ERROR, "二级分类不存在");
                }
                for (InspectItemTwoDomain two:twoDomains) {
                    if (two.getId().equals(idTwo)) {
                        indexII = twoDomains.indexOf(two);
                        List<InspectItemThreeDomain> threeDomains = two.getInspectItemThreeLists();
                        if (null == threeDomains || threeDomains.isEmpty()) {
                            return new ResDto(Const.SERVER_ERROR, "三级分类不存在");
                        }
                        for (InspectItemThreeDomain three : threeDomains) {
                            if (three.getId().equals(idThree)) {
                                indexIII = threeDomains.indexOf(three);
                                three.setStatus("1");
                            }
                        }
                        two.setInspectItemThreeLists(threeDomains);
                    }
                    one.setInspectItemTwoLists(twoDomains);
                }
                if (indexII == -1) {
                    return new ResDto(Const.SERVER_ERROR, "二级id不存在");
                }
                if (indexIII == -1) {
                    return new ResDto(Const.SERVER_ERROR, "三级id不存在");
                }
                LabInspectItemDomain save = labInspectItemRepository.save(one);
                if (save == null) {
                    return new ResDto(Const.SERVER_ERROR, "三级检查项删除失败");
                }
                ResDto resDto = new ResDto(Const.SUCCESS, "三级检查项删除成功");
                resDto.setDatas(null);
                return resDto;
            } else if (StringUtils.isNotBlank(idTwo)) {
                //直接删除二级
                LabInspectItemDomain one = labInspectItemRepository.findOne(id);
                if (one == null) {
                    return new ResDto(Const.SERVER_ERROR, "一级id不存在");
                }
                List<InspectItemTwoDomain> twoDomains = one.getInspectItemTwoLists();
                if (null == twoDomains || twoDomains.isEmpty()) {
                    return new ResDto(Const.SERVER_ERROR, "二级分类不存在");
                }
                for (InspectItemTwoDomain two : twoDomains) {
                    if (two.getId().equals(idTwo)) {
                        indexII = twoDomains.indexOf(two);
                        two.setStatus("1");
                    }
                }
                if (indexII == -1) {
                    return new ResDto(Const.SERVER_ERROR, "二级id不存在");
                }
                one.setInspectItemTwoLists(twoDomains);
                LabInspectItemDomain save = labInspectItemRepository.save(one);
                if (save == null) {
                    return new ResDto(Const.SERVER_ERROR, "二级检查项删除失败");
                }
                ResDto resDto = new ResDto(Const.SUCCESS, "二级检查项删除成功");
                resDto.setDatas(null);
                return resDto;
            } else {
                //直接删除一级
                LabInspectItemDomain one = labInspectItemRepository.findOne(id);
                if (one == null) {
                    return new ResDto(Const.SERVER_ERROR, "一级检查项id不存在");
                }
                one.setStatus("0");
                LabInspectItemDomain save = labInspectItemRepository.save(one);
                if (save == null) {
                    return new ResDto(Const.SERVER_ERROR, "二级检查项删除失败");
                }
                ResDto resDto = new ResDto(Const.SUCCESS, "一级检查项删除成功");
                resDto.setDatas(null);
                return resDto;
            }

        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SERVER_ERROR, "删除实验室信息异常");
        }

    }

    /**
     * @param labInspectItemRelationDto
     * @return
     */
    @Override
    public ResDto addConfigInspectItem(HttpServletRequest request, LabInspectItemRelationDto labInspectItemRelationDto) {
        return null;
        //        try {
//            String token = request.getHeader(Const.TOKEN_NAME);
//            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
//            if (userSessionDTO == null) {
//                return new ResDto(Const.PARAM_ERROR, "用户未登录");
//            }
//            //验证参数
//            if (StringUtils.isBlank(userSessionDTO.getId())) {
//                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
//            }
//
//            String labId = labInspectItemRelationDto.getLabId();
//            String itemIdOne = labInspectItemRelationDto.getItemIdOne();
//            String itemIdTwo = labInspectItemRelationDto.getItemIdTwo();
//            //查询labId是否可用
////        LabInspectItemRelationDomain byLabId = labInspectItemRelationRepository.findByLabId(labId);
////        if (byLabId == null) {
////            return new ResDto(Const.SERVER_ERROR, "实验室id不存在"
////        }
//
//            //从危险源隐患库中查询选中的一级检查项
//            LabInspectItemDomain selectOneDomain = labInspectItemRepository.findOne(itemIdOne);
//            if (selectOneDomain == null) {
//                return new ResDto(Const.SERVER_ERROR, "检查项一级id不存在");
//            }
//            LabInspectItemDto selectOneDto = BeanMapper.map(selectOneDomain, LabInspectItemDto.class);
//            if (StringUtils.isNotBlank(itemIdTwo)) {
//                int oneSubId = isOneSubId(selectOneDomain, itemIdTwo);
//                if (oneSubId == 1) {
//                    return new ResDto(Const.SERVER_ERROR, "二级id已经删除了");
//                } else if (oneSubId == 2) {
//                    return new ResDto(Const.SERVER_ERROR, "二级id不是一级id的子类");
//                }
//            }
//
//
//            //查询实验室是否配置了检查项
//            LabInspectItemRelationDomain relationDomain = labInspectItemRelationRepository.findByLabId(labInspectItemRelationDto.getLabId());
//            if (null == relationDomain) {
//                //没配置过实验室检查项
//                if (StringUtils.isNotBlank(itemIdTwo)) {
//                    //二级id不为空(配置时选中的是二级项)，因没有配置过，所以直接配置添加一级项和一个二级项
//                    //过滤
//                    LabInspectItemDto filterDataOnly = getFilterDataOnly(selectOneDto, itemIdTwo);
//                    if (null == filterDataOnly) {
//                        return new ResDto(Const.SERVER_ERROR, "新增检查项异常");
//                    }
//                    return addNewInspectItem(labId, filterDataOnly);
//                } else {
//                    //二级id为空(配置时选中的是一级项)，因没有配置过，所以直接配置添加一级项和全部二级项
//                    //过滤
//                    LabInspectItemDto filterDataAll = getFilterDataAll(selectOneDto);
//                    if (null == filterDataAll) {
//                        return new ResDto(Const.SERVER_ERROR, "新增添加检查项异常");
//                    }
//                    return addNewInspectItem(labId, filterDataAll);
//                }
//            } else {
//                //已经配置过实验室检查项
//                if (StringUtils.isNotBlank(itemIdTwo)) {
//                    //二级id不为空，因配置过，所以先查询配置的数据
//                    List<LabInspectItemDomain> configedList = relationDomain.getLabInspectItem();
//                    if (null != configedList && !configedList.isEmpty()) {
//                        int indexOneO = -1;
//                        for (int i = 0; i < configedList.size(); i++) {
//                            //LabInspectItemDomain configedOne = configedList.get(i);
//                            LabInspectItemDomain configedOne = new LabInspectItemDomain();
//                            BeanUtils.copyProperties(configedList.get(i), configedOne);
//                            if (configedOne.getId().equals(itemIdOne)) {
//                                indexOneO = i;
//                                // 如果已经配置数据集合中已经有传过来的一级,只添加二级就行
//                                InspectItemTwoDto filterDataOnlyTwo = getFilterDataOnlyTwo(selectOneDto, itemIdTwo);
//                                if (null == filterDataOnlyTwo) {
//                                    return new ResDto(Const.SERVER_ERROR, "添加检查项二级异常");
//                                }
//                                InspectItemTwoDomain domainTwo = new InspectItemTwoDomain();
//                                BeanUtils.copyProperties(filterDataOnlyTwo, domainTwo);
//                                //InspectItemTwoDomain domainTwo = BeanMapper.map(filterDataOnlyTwo, InspectItemTwoDomain.class);
//                                List<InspectItemTwoDomain> inspectItemTwoLists = configedOne.getInspectItemTwoLists();
//                                //中间变量
//                                List<InspectItemTwoDomain> inspectItemTwoListTemps = new ArrayList<>();
//                                if (null == inspectItemTwoLists || inspectItemTwoLists.isEmpty()) {
//                                    //说明此一级中还没有配置过二级
//                                    inspectItemTwoListTemps.add(domainTwo);
//                                } else {
//                                    //已经有二级
//                                    InspectItemTwoDomain filterDataOnlyTwoDomain = new InspectItemTwoDomain();
//                                    BeanUtils.copyProperties(filterDataOnlyTwo, filterDataOnlyTwoDomain);
//                                    if (!inspectItemTwoLists.contains(filterDataOnlyTwoDomain)) {
//                                        for (InspectItemTwoDomain domain : inspectItemTwoLists) {
//                                            inspectItemTwoListTemps.add(domain);
//                                        }
//                                        inspectItemTwoListTemps.add(domainTwo);
//                                    } else {
//                                        return new ResDto(Const.SERVER_ERROR, "检查项二级已经存在");
//                                    }
//
//                                }
//                                configedOne.setInspectItemTwoLists(inspectItemTwoListTemps);
//                                configedList.set(i, configedOne);
//                            }
//                        }
//                        if (indexOneO == -1) {
//                            // 如果已经配置数据集合中没有传过来的一级,那就要添加一级和全部二级就行
//                            LabInspectItemDto filterDataAll = getFilterDataAll(selectOneDto);
//                            if (null == filterDataAll) {
//                                return new ResDto(Const.SERVER_ERROR, "添加检查项异常了");
//                            }
//                            LabInspectItemDomain filterDataAllDomain = BeanMapper.map(filterDataAll, LabInspectItemDomain.class);
//                            configedList.set(indexOneO, filterDataAllDomain);
//                        }
//                        relationDomain.setLabInspectItem(configedList);
//                        return addToConfigedInspectItem(relationDomain, 1);
//                    }
//                    return new ResDto(Const.SERVER_ERROR, "添加检查项异常了...");
//                } else {
//                    //二级id为空(配置时选中的是一级项)，因配置过
//                    //过滤
//                    List<LabInspectItemDomain> configedList = relationDomain.getLabInspectItem();
//                    if (null != configedList && !configedList.isEmpty()) {
//                        int indexOne = -1;
//                        for (int i = 0; i < configedList.size(); i++) {
//                            LabInspectItemDomain configedOne = new LabInspectItemDomain();
//                            BeanUtils.copyProperties(configedList.get(i), configedOne);
//                            //LabInspectItemDomain configedOne = configedList.get(i);
//                            if (configedOne.getId().equals(itemIdOne)) {
//                                //因配置过，查询已经配置的数据有一级或者一级和二级就直接替换成（一级和全部二级）
//                                indexOne = i;
//                            }
//                        }
//                        if (indexOne == -1) {
//                            //没有一级,直添加一级项和全部二级项
//                            LabInspectItemDto filterDataAll = getFilterDataAll(selectOneDto);
//                            if (null == filterDataAll) {
//                                return new ResDto(Const.SERVER_ERROR, "添加检查项异常.");
//                            }
//                            LabInspectItemDomain mapM = BeanMapper.map(filterDataAll, LabInspectItemDomain.class);
//                            configedList.add(mapM);
//                            relationDomain.setLabInspectItem(configedList);
//                            return addToConfigedInspectItem(relationDomain, 1);
//                        } else {
//                            //因配置过，查询已经配置的数据有一级或者一级和二级就直接替换成（一级和全部二级）
//                            LabInspectItemDto filterDataAll = getFilterDataAll(selectOneDto);
//                            if (null == filterDataAll) {
//                                return new ResDto(Const.SERVER_ERROR, "添加检查项异常..");
//                            }
//                            LabInspectItemDomain map = BeanMapper.map(filterDataAll, LabInspectItemDomain.class);
//                            configedList.set(indexOne, map);
//                            relationDomain.setLabInspectItem(configedList);
//                            return addToConfigedInspectItem(relationDomain, 0);
//                        }
//
//                    }
//                    return new ResDto(Const.SERVER_ERROR, "添加检查项异常...");
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            return new ResDto(Const.SERVER_ERROR, "添加检查项异常..");
//        }

    }

    /**
     * 删除实验室检查项的配置
     *
     * @param labInspectItemRelationDto
     * @return
     */
    @Override
    public ResDto deleteConfigInspectItem(HttpServletRequest request, LabInspectItemRelationDto labInspectItemRelationDto) {
//        try {
//            String token = request.getHeader(Const.TOKEN_NAME);
//            UserSessionDTO userSessionDTO = iSessionService.getSessionByToken(token);
//            if (userSessionDTO == null) {
//                return new ResDto(Const.PARAM_ERROR, "用户未登录");
//            }
//            //验证参数
//            if (StringUtils.isBlank(userSessionDTO.getId())) {
//                return new ResDto(Const.SERVER_ERROR, "获取用户id失败");
//            }
//
//            String labId = labInspectItemRelationDto.getLabId();
//            String itemIdOne = labInspectItemRelationDto.getItemIdOne();
//            String itemIdTwo = labInspectItemRelationDto.getItemIdTwo();
//            LabInspectItemRelationDomain relationDomain = labInspectItemRelationRepository.findByLabId(labId);
//            if (relationDomain == null) {
//                return new ResDto(Const.SERVER_ERROR, "实验室id不存在");
//            }
//            List<LabInspectItemDomain> labInspectItemLists = relationDomain.getLabInspectItem();
//            if (null == labInspectItemLists || labInspectItemLists.isEmpty()) {
//                return new ResDto(Const.SERVER_ERROR, "无配置实验室检查项");
//            }
//            if (StringUtils.isNotBlank(itemIdTwo)) {
//                //直接删除二级
//                int indexI = -1;
//                int indexII = -1;
//                for (int i = 0; i < labInspectItemLists.size(); i++) {
//                    LabInspectItemDomain oneDomain = new LabInspectItemDomain();
//                    BeanUtils.copyProperties(labInspectItemLists.get(i), oneDomain);
//                    if (oneDomain.getId().equals(itemIdOne)) {
//                        indexI = i;
//                        List<InspectItemTwoDomain> twoDomainLists = oneDomain.getInspectItemTwoLists();
//                        if (null == twoDomainLists && twoDomainLists.isEmpty()) {
//                            return new ResDto(Const.SERVER_ERROR, "删除的实验室检查项二级id不存在，无配置实验室检查项二级");
//                        }
//                        List<InspectItemTwoDomain> twoDomainTempLists = new ArrayList<>();
//                        for (int j = 0; j < twoDomainLists.size(); j++) {
//                            InspectItemTwoDomain twoDomain = new InspectItemTwoDomain();
//                            BeanUtils.copyProperties(twoDomainLists.get(j), twoDomain);
//                            if (twoDomain.getId().equals(itemIdTwo)) {
//                                indexII = j;
//                            } else {
//                                twoDomainTempLists.add(twoDomain);
//                            }
//                        }
//                        if (indexII == -1) {
//                            return new ResDto(Const.SERVER_ERROR, "删除的实验室检查项二级id不存在");
//                        }
//                        oneDomain.setInspectItemTwoLists(twoDomainTempLists);
//                        labInspectItemLists.set(i, oneDomain);
//                    }
//                }
//                if (indexI == -1) {
//                    return new ResDto(Const.SERVER_ERROR, "删除的实验室检查项一级id不存在");
//                }
//                //labInspectItemLists 这个不会为空的现在删除的是二级项，它还会有一级，
//                relationDomain.setLabInspectItem(labInspectItemLists);
//                return addToConfigedInspectItem(relationDomain, 3);
//            }
//            if (StringUtils.isNotBlank(itemIdOne)) {
//                //删除一级和一级下面所有的二级
//                int indexOne = -1;
//                List<LabInspectItemDomain> labInspectItemTempList = new ArrayList<>();
//                for (int k = 0; k < labInspectItemLists.size(); k++) {
//                    LabInspectItemDomain oneDomain = new LabInspectItemDomain();
//                    BeanUtils.copyProperties(labInspectItemLists.get(k), oneDomain);
//                    if (oneDomain.getId().equals(itemIdOne)) {
//                        indexOne = k;
//                    } else {
//                        labInspectItemTempList.add(oneDomain);
//                    }
//                }
//                if (indexOne == -1) {
//                    return new ResDto(Const.SERVER_ERROR, "删除的实验室检查项一级id不存在");
//                }
//                if (null == labInspectItemTempList || labInspectItemTempList.isEmpty()) {
//                    //把一级全删除完了,所以要在表中要删除这条记录
//                    try {
//                        labInspectItemRelationRepository.delete(labId);
//                        return new ResDto(Const.SERVER_ERROR, "删除的实验室检查项一级成功");
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                        return new ResDto(Const.SERVER_ERROR, "删除的记录异常");
//                    }
//                }
//                relationDomain.setLabInspectItem(labInspectItemTempList);
//                return addToConfigedInspectItem(relationDomain, 2);
//            }
//            return new ResDto(Const.SERVER_ERROR, "出错啦");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return new ResDto(Const.SERVER_ERROR, "异常啦");
//        }
        return null;
    }

    /**
     * 二级id是一级id的子类吗？
     * 0 是  1 是但已经删除  2 不是
     *
     * @param twoId
     * @return
     */
    private int isOneSubId(LabInspectItemDomain selectOneDomain, String twoId) {
        //二级id是否一级id的子类且不是已经逻辑删除的
        List<InspectItemTwoDomain> inspectItemTwoLists = selectOneDomain.getInspectItemTwoLists();
        if (null == inspectItemTwoLists || inspectItemTwoLists.isEmpty()) {
            return 2;
        }
        int indexTwo = -1;
        for (int i = 0; i < inspectItemTwoLists.size(); i++) {
            InspectItemTwoDomain domain = new InspectItemTwoDomain();
            BeanUtils.copyProperties(inspectItemTwoLists.get(i), domain);
            if (domain.getId().equals(twoId)) {
                indexTwo = i;
                if (!domain.getStatus().equals("0")) {
                    return 1;
                }
            }
        }
        if (indexTwo == -1) {
            return 2;
        }
        return 0;
    }

    /**
     * 添加到已经配置的检查项中去
     * type 0集合替换 1集合添加 2删除一级检查项成功 3删除二级检查项成功
     *
     * @param relationDomain
     * @return
     */
    private ResDto addToConfigedInspectItem(LabInspectItemRelationDomain relationDomain, int type) {
        try {
            LabInspectItemRelationDomain save = labInspectItemRelationRepository.save(relationDomain);
            ResDto resDto;
            if (save == null) {
                if (type == 0) {
                    resDto = new ResDto(Const.SERVER_ERROR, "检查项配置替换失败");
                } else if (type == 2) {
                    resDto = new ResDto(Const.SERVER_ERROR, "删除一级检查项失败");
                } else if (type == 3) {
                    resDto = new ResDto(Const.SERVER_ERROR, "删除二级检查项失败");
                } else {
                    resDto = new ResDto(Const.SERVER_ERROR, "检查项添加失败");
                }
                resDto.setDatas(null);
                return resDto;
            }

            if (type == 0) {
                resDto = new ResDto(Const.SUCCESS, "检查项替换成功");
            } else if (type == 2) {
                resDto = new ResDto(Const.SUCCESS, "删除一级检查项成功");
            } else if (type == 3) {
                resDto = new ResDto(Const.SUCCESS, "删除二级检查项成功");
            } else {
                resDto = new ResDto(Const.SUCCESS, "检查项添加成功");
            }
            resDto.setDatas(null);
            return resDto;
        } catch (Exception e) {
            e.printStackTrace();
            return new ResDto(Const.SERVER_ERROR, "数据记录处理异常");
        }
    }

    /**
     * 新增配置的检查项
     *
     * @param labId
     * @param filterDataOnly
     * @return
     */
    private ResDto addNewInspectItem(String labId, LabInspectItemDto filterDataOnly) {
//        LabInspectItemDomain map = BeanMapper.map(filterDataOnly, LabInspectItemDomain.class);
//        List<LabInspectItemDomain> labInspectItemList = new ArrayList<>();
//        labInspectItemList.add(map);
//        LabInspectItemRelationDomain relationDomainNew = new LabInspectItemRelationDomain();
//        relationDomainNew.setLabInspectItem(labInspectItemList);
//        relationDomainNew.setLabId(labId);
//        // TODO: 2018/6/7
//        relationDomainNew.setCreateUserId("aaad");
//        relationDomainNew.setGmtModified(new Date());
//        relationDomainNew.setGmtCreated(new Date());
//        LabInspectItemRelationDomain save = labInspectItemRelationRepository.save(relationDomainNew);
//        ResDto resDto = new ResDto();
//        if (save == null) {
//            resDto.setDatas(null);
//            resDto.setMsg("添加检查项失败");
//            resDto.setStatus(Const.SERVER_ERROR);
//            return resDto;
//        }
//        resDto.setDatas(null);
//        resDto.setMsg("添加检查项成功");
//        resDto.setStatus(Const.SUCCESS);
//        return resDto;

        return null;
    }

    /**
     * 获取过滤的检查项数据
     * 返回对象（一级 和 [二级全部]（不要三级））
     * 过滤去掉了一级和二级status=1的数据
     */
    private LabInspectItemDto getFilterDataAll(LabInspectItemDto oneInspectItemDto) {
        if (oneInspectItemDto.getStatus().equals("1")) {
            return null;
        }
        List<InspectItemTwoDto> twoDtoList = oneInspectItemDto.getInspectItemTwoLists();
        if (null == twoDtoList || twoDtoList.isEmpty()) {
            oneInspectItemDto.setInspectItemTwoLists(null);
        } else {
            //过滤掉status=1
            List<InspectItemTwoDto> twoDtoListTemp = new ArrayList<>();
            for (int i = 0; i < twoDtoList.size(); i++) {
                //类型转换问题
                InspectItemTwoDto twoDto = new InspectItemTwoDto();
                BeanUtils.copyProperties(twoDtoList.get(i), twoDto);
                //InspectItemTwoDto twoDto = twoDtoList.get(i);
                if (twoDto.getStatus().equals("0")) {
                    twoDto.setInspectItemThreeLists(null);
                    twoDtoListTemp.add(twoDto);
                }
            }
            oneInspectItemDto.setInspectItemTwoLists(twoDtoListTemp);
        }
        return oneInspectItemDto;
    }

    /**
     * 获取过滤的检查项数据
     * 返回对象（一级 和 [一个二级]（不要三级））
     * 过滤去掉了一级和二级status=1的数据
     *
     * @param selectOneDto 从隐患库中查询出来的
     * @return
     */
    private LabInspectItemDto getFilterDataOnly(LabInspectItemDto selectOneDto, String itemTwoId) {
        if (selectOneDto.getStatus().equals("1")) {
            return null;
        }
        List<InspectItemTwoDto> twoDtoList = selectOneDto.getInspectItemTwoLists();
        if (null == twoDtoList || twoDtoList.isEmpty()) {
            selectOneDto.setInspectItemTwoLists(null);
        } else {
            //过滤掉status=1
            List<InspectItemTwoDto> twoDtoListTemp = new ArrayList<>();
            for (int i = 0; i < twoDtoList.size(); i++) {
                //InspectItemTwoDto twoDto = twoDtoList.get(i);
                InspectItemTwoDto twoDto = new InspectItemTwoDto();
                BeanUtils.copyProperties(twoDtoList.get(i), twoDto);
                if (twoDto.getStatus().equals("0") && twoDto.getId().equals(itemTwoId)) {
                    twoDto.setInspectItemThreeLists(null);
                    twoDtoListTemp.add(twoDto);
                }
            }
            if (null == twoDtoListTemp || twoDtoListTemp.isEmpty()) {
                //二级id不存在或者已经删除
                selectOneDto.setInspectItemTwoLists(null);
            } else {
                selectOneDto.setInspectItemTwoLists(twoDtoListTemp);
            }
        }
        return selectOneDto;
    }

    /**
     * 获取过滤的检查项数据
     * 返回对象（ [只有一个二级]（不要三级））
     * 过滤去掉了一级和二级status=1的数据
     *
     * @param oneInspectItemDto
     * @param itemTwoId
     * @return
     */
    private InspectItemTwoDto getFilterDataOnlyTwo(LabInspectItemDto oneInspectItemDto, String itemTwoId) {
        if (oneInspectItemDto.getStatus().equals("1")) {
            return null;
        }
        List<InspectItemTwoDto> twoDtoList = oneInspectItemDto.getInspectItemTwoLists();
        InspectItemTwoDto twoDtoTemp = null;
        if (null != twoDtoList && !twoDtoList.isEmpty()) {
            //过滤掉status=1
            for (int i = 0; i < twoDtoList.size(); i++) {
                //InspectItemTwoDto twoDto = twoDtoList.get(i);
                InspectItemTwoDto twoDto = new InspectItemTwoDto();
                BeanUtils.copyProperties(twoDtoList.get(i), twoDto);
                if (twoDto.getStatus().equals("0") && twoDto.getId().equals(itemTwoId)) {
                    twoDto.setInspectItemThreeLists(null);
                    twoDtoTemp = twoDto;
                }
            }
        }
        return twoDtoTemp;
    }

    /**
     * 过滤数据（一级和二级和三级）
     * 去除status=1
     *
     * @param labInspectItemDtoList
     * @return
     */
    public ResDto getFilterInspectItemList(List<LabInspectItemDto> labInspectItemDtoList) {
        ResDto resDto = new ResDto(ConstEum.SUCCESS);
        if (null == labInspectItemDtoList || labInspectItemDtoList.isEmpty()) {
            resDto.setDatas(null);
            resDto.setMsg("没有符合条件的数据");
            return resDto;
        }
        //中间变量
        List<LabInspectItemDto> oneTempList = new ArrayList<>();
        for (int i = 0; i < labInspectItemDtoList.size(); i++) {
            LabInspectItemDto one = labInspectItemDtoList.get(i);
            if (one.getStatus().equals("0")) {
                List<InspectItemTwoDto> twoDtoLists = one.getInspectItemTwoLists();
                List<InspectItemTwoDto> twoTempList = new ArrayList<>();
                if (null != twoDtoLists && !twoDtoLists.isEmpty()) {
                    for (int j = 0; j < twoDtoLists.size(); j++) {
                        InspectItemTwoDto two = new InspectItemTwoDto();
                        BeanUtils.copyProperties(twoDtoLists.get(j), two);
                        //InspectItemTwoDto two = twoDtoLists.get(j);
                        if (two.getStatus().equals("0")) {
                            List<InspectItemThreeDto> threeDomains = two.getInspectItemThreeLists();
                            List<InspectItemThreeDto> threeTempList = new ArrayList<>();
                            if (null != threeDomains && !threeDomains.isEmpty()) {
                                for (int k = 0; k < threeDomains.size(); k++) {
                                    //why
                                    //InspectItemThreeDto three = threeDomains.get(k);
                                    InspectItemThreeDto three = new InspectItemThreeDto();
                                    BeanUtils.copyProperties(threeDomains.get(k), three);
                                    if (three.getStatus().equals("0")) {
                                        threeTempList.add(three);
                                    }
                                }
                                //把集合添加到对象中去
                                if (null == threeTempList || threeTempList.isEmpty()) {
                                    two.setInspectItemThreeLists(null);
                                } else {
                                    two.setInspectItemThreeLists(threeTempList);
                                }

                            }
                            twoTempList.add(two);
                        }
                    }
                    //把集合添加到对象中去
                    if (null == twoTempList || twoTempList.isEmpty()) {
                        one.setInspectItemTwoLists(null);
                    } else {
                        one.setInspectItemTwoLists(twoTempList);
                    }

                }
                oneTempList.add(one);
            }
        }
        resDto.setDatas(JsonMapper.defaultMapper().toJson(oneTempList));
        resDto.setMsg("成功");
        return resDto;
    }

    /**
     * 获取危险源隐患库--根据分类只显示一级和二级检查项
     * 过滤数据（一级和二级）去除status=1
     *
     * @param labInspectItemDtoList
     * @return
     */
    public ResDto getFilterInspectItemList_two(List<LabInspectItemDto> labInspectItemDtoList) {
        ResDto resDto = new ResDto(ConstEum.SUCCESS);
        if (null == labInspectItemDtoList || labInspectItemDtoList.isEmpty()) {
            resDto.setDatas(null);
            resDto.setMsg("没有符合条件的数据");
            return resDto;
        }
        //用中间变量
        List<LabInspectItemDto> oneTempList = new ArrayList<>();
        for (int i = 0; i < labInspectItemDtoList.size(); i++) {
            LabInspectItemDto one = labInspectItemDtoList.get(i);
            if (one.getStatus().equals("0")) {
                List<InspectItemTwoDto> twoDtoLists = one.getInspectItemTwoLists();
                List<InspectItemTwoDto> twoTempList = new ArrayList<>();
                if (null != twoDtoLists && !twoDtoLists.isEmpty()) {
                    for (int j = 0; j < twoDtoLists.size(); j++) {
                        //类型转换异常 用下面的方法：
                        InspectItemTwoDto two = new InspectItemTwoDto();
                        BeanUtils.copyProperties(twoDtoLists.get(j), two);
                        //InspectItemTwoDto two = twoDtoLists.get(j);
                        if (two.getStatus().equals("0")) {
                            twoTempList.add(two);
                        }
                    }
                    //把集合添加到对象中去
                    if (null == twoTempList || twoTempList.isEmpty()) {
                        one.setInspectItemTwoLists(null);
                    } else {
                        one.setInspectItemTwoLists(twoTempList);
                    }

                }
                oneTempList.add(one);
            }
        }
        resDto.setDatas(JsonMapper.defaultMapper().toJson(oneTempList));
        resDto.setMsg("成功");
        return resDto;
    }
}
